// JavaScript Document

jQuery(function() {
	$.fn.imageLoaded = function( callback ){
		var $this = this[0];

		var timer  = setInterval(function(){
			if($this.complete == true) {
				clearInterval(timer);
				callback.call($this);
			}
		},200);

		return $this;
	};



});


jQuery(function() {

	var $my_images = $('.cols.benefits img');
	$my_images.css({'opacity':'0','visibility':'visible'});

	$my_images.each( function() {
		$(this).imageLoaded(function(){

			$(this).animate({'opacity':'1'}, 500);

		});
	});

});

jQuery(function() {

	var $my_images = $('.widget_img img, .news_ico img, .comment_author img, .our_clients img');
	$my_images.css({'opacity':'0','visibility':'visible'});

	$my_images.each( function() {
		$(this).imageLoaded(function(){

			$(this).animate({'opacity':'1'}, 500);

		});
	});

});

jQuery(function() {

	var $my_images = $('img.frame-img, .gallery-item img, .blog_ico img');
	$my_images.wrap('<div class="loading-image" />').css({'opacity':'0','visibility':'visible'});

	$my_images.each( function() {
		$(this).imageLoaded(function(){

			$(this).animate({'opacity':'1'}, 500, function(){
				$(this).unwrap();
			});

		});
	});

});

function preloadGallery(){
	var $my_images = $('.cols.benefits img');
	$my_images.css({'opacity':'0','visibility':'visible'});
	
	$my_images.each( function() {
		$(this).imageLoaded(function(){

			$(this).animate({'opacity':'1'}, 500, function(){
//				$(this).unwrap();
			});

		});
	});
}